package com.yunpuvip.sachet.rest.config.properties;

import cn.stylefeng.roses.core.util.ToolUtil;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.io.File;

/**
 * 项目相关配置
 *
 * @author fengshuonan
 * @date 2017年10月23日16:44:15
 */
@Configuration
@ConfigurationProperties(prefix = RestProperties.REST_PREFIX)
public class RestProperties {

    public static final String REST_PREFIX = "rest";

    private boolean authOpen = true;

    private boolean signOpen = true;

    private String restUploadPath = "";

    public boolean isAuthOpen() {
        return authOpen;
    }

    public void setAuthOpen(boolean authOpen) {
        this.authOpen = authOpen;
    }

    public boolean isSignOpen() {
        return signOpen;
    }

    public void setSignOpen(boolean signOpen) {
        this.signOpen = signOpen;
    }

    public String getRestUploadPath() {
        //如果没有写文件上传路径,保存到临时目录
        if (ToolUtil.isEmpty(restUploadPath)) {
            return ToolUtil.getTempPath();
        } else {
            if (!restUploadPath.endsWith(File.separator)) {
                restUploadPath = restUploadPath + File.separator;
            }
            //判断目录存不存在,不存在创建
            File file = new File(restUploadPath);
            if (!file.exists()) {
                file.mkdirs();
            }
            return restUploadPath;
        }
    }

    public void setRestUploadPath(String restUploadPath) {
        this.restUploadPath = restUploadPath;
    }
}
